IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_MasterEventLogType_SrvrInstnc]') AND parent_object_id = OBJECT_ID(N'[dbo].[MasterEventLogType]'))
BEGIN
     ALTER TABLE [dbo].[MasterEventLogType] DROP CONSTRAINT [FK_MasterEventLogType_SrvrInstnc]
END
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MasterEventLogType]') AND type in (N'U'))
BEGIN
     DROP TABLE [dbo].[MasterEventLogType]
END
GO

CREATE TABLE [dbo].[MasterEventLogType](
     [SrvrInstncDatabaseId] [int]         NOT NULL,
     [EventLogTypeId]       [int]         NOT NULL,
     [EventLogTypeCd]       [varchar](5)  NOT NULL,
     [EventLogTypeDesc]     [varchar](15) NOT NULL,
     CONSTRAINT [PK_MasterEventLogType] PRIMARY KEY CLUSTERED 
          ( [SrvrInstncDatabaseId] ASC, [EventLogTypeId] ASC )
)
GO

CREATE UNIQUE NONCLUSTERED INDEX [IX_MasterEventLogType_EventLogTypeCd] ON [dbo].[MasterEventLogType] 
     ( [SrvrInstncDatabaseId] ASC, [EventLogTypeCd] ASC )
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Unique Identifier of a particular Database on a Database Server Instance.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'MasterEventLogType', @level2type=N'COLUMN',@level2name=N'SrvrInstncDatabaseId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Unique Identifier of a particular Event Log Type.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'MasterEventLogType', @level2type=N'COLUMN',@level2name=N'EventLogTypeId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Secondary Unique Identifier of a particular Event Log Type, user defined.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'MasterEventLogType', @level2type=N'COLUMN',@level2name=N'EventLogTypeCd'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Description of Event Log Type.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'MasterEventLogType', @level2type=N'COLUMN',@level2name=N'EventLogTypeDesc'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Combined event logging types.  Contains list of event log types from one or more server instance databases.  Normally matches delivered 4 items per server instance database.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'MasterEventLogType'
GO
